﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EnvironmentManagerSystem.MODE;
using EnvironmentManagerSystem.BLL;

namespace EnvironmentManagerSystem
{
    public partial class AddSubBasicData : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (StfInfo.ReSession()) return; if (!IsPostBack)
            {
                BindingBigKindList();
            }
        }

        private void BindingBigKindList()
        {
            this.ddlMainKindName.Items.Clear();
            BasicDataMainDataCollection lst = BasicData.GetBigList();
            if (lst != null)
            {
                for (int i = 0; i < lst.Count; i++)
                {
                    ddlMainKindName.Items.Add(lst[i].DataKindName);
                }
            }
        }

        protected void btnOk_Click(object sender, EventArgs e)
        {
            if (txtMainKindName.Text == string.Empty)
            {
                Jscript.Alert("类别名称不能为空", this);
                return;
            }
            if (txtMainKindName.Text.Length > 25)
            {
                Jscript.Alert("类别名称不能大于25个字", this);
                return;
            }
            if (txtMainKindMemo.Text.Length > 25)
            {
                Jscript.Alert("类别名称不能大于250个字", this);
                return;
            }
            BasicDataSubData model = new BasicDataSubData();
            model.MainID = BasicData.GetMainIDbyName(this.ddlMainKindName.SelectedItem.Text.Trim());
            model.DataValue = txtMainKindName.Text.Trim();
            model.DataValueMemo = txtMainKindMemo.Text.Trim();
            if (BasicData.InsertSubBasicData(model) > 0)
            {
                Response.Write("<script>alert('添加成功');window.parent.art.dialog.list['添加小类'].close();</script>");
            }
            else
            {
                Jscript.Alert("添加失败,请检查数据库!", this);
            }
        }

        #region 按钮(取消)(x)
        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Write("<script>window.parent.art.dialog.list['添加小类'].close();</script>");
        }
        #endregion
    }
}
